package com.victualler.product.goods.service.impl;

import com.victualler.core.base.service.impl.BaseDetailServiceImpl;
import com.victualler.product.goods.entity.GoodsModelDetailDao;
import com.victualler.product.goods.repository.GoodsModelDetailQueryRepository;
import com.victualler.product.goods.repository.GoodsModelDetailRepository;
import com.victualler.product.goods.service.GoodsModelDetailService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Guoshichang
 * @Date: Create in 10:09 2018-05-06
 * @Discription:
 */
@Service
public class GoodsModelDetailServiceImpl extends BaseDetailServiceImpl<GoodsModelDetailDao,GoodsModelDetailRepository,GoodsModelDetailQueryRepository> implements GoodsModelDetailService {
    /**
     * @author Guoshichang   
     * @since 21:05 on 2018/12/7.
     * @Function  统一刷条形码
     */
    public void flushModelBarId() {
        List<GoodsModelDetailDao> list = this.baseRepository.findAll();
        for (GoodsModelDetailDao goodsModelDetailDao : list) {
            if ("-1".equals(goodsModelDetailDao.getBarCode())) {
                String barCode ="" + goodsModelDetailDao.getParentId() + goodsModelDetailDao.getId();
                barCode = String.format("%016d",Long.parseLong(barCode));
                System.out.println("生成随机条形码:" + barCode);
                goodsModelDetailDao.setBarCode(barCode);
            }
        }
        this.baseRepository.save(list);
    }
}
